player.list.clear();
$('#address').text('输入“我想听xx”可点播');
$('.primary').hide();
client.onMessageArrived = function(message){

	var receive_topic = message.destinationName;
	var receive_content = message.payloadString;
	    receive_content = JSON.parse(receive_content);
    client.debugMessage(receive_content);

	// 收到聊天记录时
	if(receive_content.message){
	    $('.chatContent').append(
	        $("<div>",{
	            'text':receive_content.message,
	            'class':'chatItem'
	        }),
	    );
	    $('.chatContent').scrollTop($('.chatContent:first')[0].scrollHeight - $('.chatContent:first')[0].clientHeight);
	}

	// 更新在线人数
    if(receive_content.totalMember){
        $('#totalMember').text(receive_content.totalMember);
    }

	// 收到歌曲信息时
	if(receive_content.audio){
	    if(receive_content.audio.url != player.audio.currentSrc){
	        // 清空歌单
	        player.list.clear();
	        // 加入歌单
	        player.list.add([{
	            name: receive_content.audio.name,
	            artist: receive_content.audio.artist,
	            url: receive_content.audio.url,
	            cover: receive_content.audio.cover,
	        }]);
	    }
	    // 播放内容
	    if(receive_content.status  && receive_content.status ==1){
	        player.play();
	    }else{
	        player.pause()
	    }
	    player.audio.currentTime = receive_content.seek;
	}
}


client.onConnectionSuccess = function(message){
    client.debugMessage('服务器连接成功');
    client.subscribe(topic);
    client.subscribe(subscribeTopic);

    // 主动询问广播端,要求同步此次播放信息 
    var message = JSON.stringify({
        'action': 'SYNCSTATUS',
        'topic': topic,
        'clientId': clientId,
    });
    client.sendMessage(subscribeTopic,message);

}


// 聊天
$('.chatInput').on('keydown',function(e){
    _keyword = $(this).val();
    if(e.keyCode==13 || e.keyCode==108){
        $(this).val('');
        var message = JSON.stringify({
            'message':_keyword,
            'clientId':clientId,
        });
        client.sendMessage(subscribeTopic,message);
    }
});




setInterval(function(){
	var message = JSON.stringify({
        'action': 'ALIVE',
        'clientId':clientId,
    });
    client.sendMessage(subscribeTopic,message);
	// console.log('我还活着');
},5000);
